package com.ruicar.afs.cloud.apply.business.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.apply.business.condition.WorkflowRecordDetailsCondition;
import com.ruicar.afs.cloud.apply.business.service.ApplyRecordDetailsService;
import com.ruicar.afs.cloud.apply.common.entity.WorkflowRecordDetails;
import com.ruicar.afs.cloud.apply.pre.loan.vo.WorkRecordDetailsVO;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 审批记录controller
 *
 * @author 耿继辉
 */
@RestController
@Slf4j
@AllArgsConstructor
@ApiOperation("审批记录controller")
@RequestMapping("/record")
public class ApplyRecordDetailsController {
    private ApplyRecordDetailsService applyRecordDetailsService;

    /**
     * 多条件查询审批记录信息
     * 业务编号，审批结果，流程ID,流程类型
     *
     * @param condition
     * @return
     */
    @PostMapping("/getWorkFlowRecordInfo")
    @ApiOperation("多条件查询审批记录信息")
    public IResponse<WorkflowRecordDetails> getWorkFlowRecordInfo(@RequestBody WorkflowRecordDetailsCondition condition) {
        WorkRecordDetailsVO recordInfo = applyRecordDetailsService.getRecordInfo(condition);
        return IResponse.success(recordInfo);
    }

    /**
     * <p>description：</p>
     * 根据业务编号查询审批记录信息
     *
     * @param condition 审批记录查询条件
     * @auth ma_xueyu
     * @date 2020年9月10日
     */
    @PostMapping("/getWorkflowRecordListByBusinessNo")
    @ApiOperation("根据业务编号查询审批记录信息")
    public IResponse<List<WorkflowRecordDetails>> getWorkflowRecordListByApplyNo(@RequestBody WorkflowRecordDetailsCondition condition) {
        List<WorkflowRecordDetails> recordDetailsList = applyRecordDetailsService.list(Wrappers.<WorkflowRecordDetails>query().lambda()
                .eq(WorkflowRecordDetails::getBusinessNo, condition.getBusinessNo()));
        return IResponse.success(recordDetailsList);
    }
}
